package com.pdg.mcplugin.spawnsurance.commandprocessors;

import org.bukkit.command.CommandSender;

import com.pdg.mcplugin.common.ArgumentList;
import com.pdg.mcplugin.common.baseclasses.CommandProcessorBase;
import com.pdg.mcplugin.spawnsurance.SpawnSurance;

public class GetClaimsForCommandProcessor extends
		CommandProcessorBase<SpawnSurance> {

	private static final String messageSuccess = "Player '%s' has '%d' claims.";

	public GetClaimsForCommandProcessor(SpawnSurance thePlugin) {
		super(thePlugin, new String[]{
				"/spawnsurance get claims-for (player name) - gets the claims for a particular player name"
		});
	}

	@Override
	protected boolean specialProcessCommand(CommandSender theCommandSender,
			String theSubCommand, ArgumentList theArgumentList) {
		if(!getPlugin().getPermissionChecker().checkPermission(theCommandSender, Property.CLAIMS_FOR.getGetPermission())){
			return false;
		}
		try{
			String thePlayerName = theSubCommand;
			Integer theClaims = getPlugin().getDataProvider().retrievePlayerClaims(thePlayerName);
			getPlugin().sendSuccessMessage(theCommandSender, String.format(messageSuccess,thePlayerName,theClaims));
			return true;
		}catch(Exception e){
			getPlugin().getLogger().severe(e.getMessage());
			return false;
		}
	}

}
